*****************************************************************
*****************************************************************
*** 0. General settings
*****************************************************************
*****************************************************************

* clear
clear
clear 		mata
mat 		drop _all

* set path
global		path	""					



use "$path/0 Data/_Processed/BHC_Bank_Ratios.dta", clear

merge m:m entity using "$path/0 Data/_Processed/sample"
keep if _merge == 3
drop _merge

keep if year == 2019
keep if date == td(31Dec2019)

sum liquidity_risk, d

gen high_liq = (liquidity_risk >= r(p50))

keep gvkey name high_liq
save "$path/0 Data/_Processed/sample_high_liq.dta", replace



*SP500 for beta-adjusted return
use "$path/0 Data/_Processed/sp500-ret_2000-2020_daily", clear
keep if year(date) == 2020 
rename date datadate
save "$path/0 Data/_Processed/sp500-ret_2020_daily", replace


use "$path/0 Data/_Processed/crsp_2020_figure", clear

destring gvkey, replace
 

merge m:m gvkey using "$path/0 Data/_Processed/sample"
keep if _merge == 3
drop _merge


merge m:m gvkey using "$path/0 Data/_Processed/sample_high_liq.dta"
keep if _merge == 3
drop _merge

merge 	m:1 entity using  "$path/0 Data/_Processed/US_Bank_Betas_2019Q4"
keep 	if _merge == 3
drop 	_merge

merge 	m:1 datadate using  "$path/0 Data/_Processed/sp500-ret_2020_daily"
keep 	if _merge == 3
drop 	_merge

*beta-adjusted return
gen 	beta = .
forvalues k = 12(12)60 {
		replace beta 				= bank_beta_`k'm 				if bank_beta_`k'm != . 
}
replace return = return - beta*return_sp_daily


collapse (mean) return [aweight = mv], by(high_liq datadate)
rename return w_ret


** Figure. stock price development

generate index2 = .
replace	index2 = 100 if datadate == td(02jan2020)
by  high_liq (datadate), sort: replace index2 = index2[_n-1] * (1+w_ret) if index2 == .

tsset high_liq datadate

twoway (tsline index2 if high_liq==1) (tsline index2 if high_liq==0), ///
	legend(label(1 "High Liquidity Risk") label(2 "Low Liquidity Risk")) ///
 	scheme(s2mono) ///
	ylabel(, angle(horizontal)) ///
	xlabel(`=d(1feb2020)' `=d(1apr2020)' `=d(1june2020)' `=d(1aug2020)' `=d(1oct2020)' `=d(1dec2020)' , format(%tdMon-CCYY)) ///
	xtitle("Date")		///
	ytitle("Stock Price")		///
	ylabel(, angle(horizontal)) ///
	note("")   ///			
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
	graph export  "$path/05 Figures/Figure 3 Panel A1.png",replace


	
	

preserve

keep if high_liq == 1
ren index2 index2_high
save "$path/0 Data/_Processed/temp_high_liq.dta", replace

restore

drop if high_liq == 1

merge 1:1 datadate using "$path/0 Data/_Processed/temp_high_liq.dta"
drop _merge


gen delta_stock = index2_high - index2


* Figure - stock price differential

tsset datadate

rename delta_stock delta_stock_liq
merge 1:1 datadate using "$path/0 Data/_Processed/temp_stock_delta_commitment.dta"

twoway (tsline delta_stock_liq) (tsline delta_stock), ///
	legend(label(1 "Liquidity Risk") label(2 "Credit Line Commitments")) ///
 	scheme(s2mono) ///
	ylabel(, angle(horizontal)) ///
	xlabel(`=d(1feb2020)' `=d(1apr2020)' `=d(1june2020)' `=d(1aug2020)' `=d(1oct2020)' `=d(1dec2020)' , format(%tdMon-CCYY)) ///
	xtitle("Date")		///
	ytitle("Stock Price Difference (High vs. Low)")		///
	ylabel(, angle(horizontal)) ///
	note("")   ///			
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
	graph export  "$path/05 Figures/Figure 3 Panel A2.png",replace
